package com.cradom.event.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cradom.event.model.Event;
import com.cradom.event.service.EventService;

@Controller
@RequestMapping("/event")
public class EventController {
	
	@Resource
	private EventService eventService;
	
	/**
	 * 首页有关的事件信息在IntexController里
	 * 这方法是根据事件id获取事件内容
	 * @param request
	 * @param id
	 * @return
	 */
	@RequestMapping("/eventDetail")
	public String getEventDetail(HttpServletRequest request,@RequestParam("id")String id){
		Event event=eventService.getEventDetail(id);
		if(event!=null){
			request.setAttribute("event",event);
			return "forward:/eventDetail.jsp";
		}else{
			return "redirect:/error.jsp";
		}
	}
	
	@RequestMapping("/search")
	public String findEventByChildrenName(@RequestParam("name")String name,HttpServletRequest request){
		List<Event> list=eventService.findEventByChildrenName(name);
		request.setAttribute("list", list);
		return "forward:/search.jsp";
	}
}
